﻿using System;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
    public class UserRoleRepository : BaseRepository<UserRole>, IUserRoleRepository
	{
        public UserRoleRepository(IContextContainer container)
            : base(container)
		{
		}

		public void InsertOnSubmit(UserRole entity)
		{
			Context.UserRoles.AddObject(entity);
		}

        public void Update(UserRole entity)
		{
            Context.UserRoles.Attach(entity);
			Context.ObjectStateManager.GetObjectStateEntry(entity).SetModified();
		}

        public void DeleteOnSubmit(UserRole entity)
		{
            Context.UserRoles.DeleteObject(entity);
		}

		public void SubmitChanges()
		{
			SaveChanges();
		}

        public IQueryable<UserRole> GetAll()
        {
            return CurrentObjectQuery;
        }

        public IQueryable<UserRole> Where(Expression<Func<UserRole, bool>> predicate)
		{
			return CurrentObjectQuery.Where(predicate);
		}

        public long Count(Expression<Func<UserRole, bool>> predicate)
		{
			return CurrentObjectQuery.Count(predicate);
		}

		public IUserRoleRepository Include(params string[] paths)
		{
			CurrentObjectQuery = CreateObjectQuery().Include(paths);
			return this;
		}

		#region IReadOnlyRepository<IUserRoleRepository,UserRole> Members


		public IUserRoleRepository EnableLazyLoading()
		{
			SetLazyLoading(true);
			return this;
		}

		public IUserRoleRepository DisableLazyLoading()
		{
			SetLazyLoading(false);
			return this;
		}

		#endregion
	}
}